package com.dycx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dycx.user.converter.UserInfoConverter;
import com.dycx.user.entity.UserInfoDO;
import com.dycx.user.mapper.UserInfoMapper;
import com.dycx.user.service.UserInfoService;
import com.dycx.user.vo.UserInfoVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class UserInfoImpl extends ServiceImpl<UserInfoMapper, UserInfoDO> implements UserInfoService {

    @Override
    public UserInfoVO load(Integer uid) {
        LambdaQueryWrapper<UserInfoDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfoDO::getUid, uid);

        UserInfoDO userInfoDO = this.getOne(queryWrapper);
        return UserInfoConverter.entityToVo(userInfoDO);
    }

    @Override
    public List<UserInfoVO> getList(List<Integer> uids) {
        LambdaQueryWrapper<UserInfoDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(UserInfoDO::getUid, uids);

        List<UserInfoDO> userInfoDOList = this.list(queryWrapper);
        return UserInfoConverter.entityToVoList(userInfoDOList);
    }

    @Override
    public Boolean edit(UserInfoDO userInfoDO) {
        LambdaQueryWrapper<UserInfoDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfoDO::getUid, userInfoDO.getUid());

        return update(userInfoDO, queryWrapper);
    }
}
